package com.education.platform.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.time.LocalDateTime;

/**
 * 消息发送记录表
 *
 * @author education-platform
 * @since 2024-10-07
 */
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("message_send_log")
public class MessageSendLog {

    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 模板编码
     */
    @TableField("template_code")
    private String templateCode;

    /**
     * 接收者类型
     */
    @TableField("recipient_type")
    private String recipientType;

    /**
     * 接收者ID列表
     */
    @TableField("recipient_ids")
    private String recipientIds;

    /**
     * 发送类型
     */
    @TableField("send_type")
    private String sendType;

    /**
     * 消息标题
     */
    @TableField("title")
    private String title;

    /**
     * 消息内容
     */
    @TableField("content")
    private String content;

    /**
     * 发送数量
     */
    @TableField("send_count")
    private Integer sendCount;

    /**
     * 成功数量
     */
    @TableField("success_count")
    private Integer successCount;

    /**
     * 失败数量
     */
    @TableField("failed_count")
    private Integer failedCount;

    /**
     * 发送状态
     */
    @TableField("status")
    private String status;

    /**
     * 错误信息
     */
    @TableField("error_message")
    private String errorMessage;

    /**
     * 发送时间
     */
    @TableField("sent_at")
    private LocalDateTime sentAt;

    /**
     * 创建时间
     */
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;

    // 枚举定义
    public enum RecipientType {
        USER("指定用户"),
        ROLE("指定角色"),
        ALL("全部用户");

        private final String description;

        RecipientType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    public enum SendType {
        SYSTEM("系统消息"),
        SMS("短信"),
        EMAIL("邮件"),
        PUSH("推送");

        private final String description;

        SendType(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }

    public enum Status {
        PENDING("待发送"),
        SENDING("发送中"),
        SUCCESS("发送成功"),
        PARTIAL_SUCCESS("部分成功"),
        FAILED("发送失败");

        private final String description;

        Status(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }
    }
}
